package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：能源数据键值转换
 * @Date：Create by 2023-12-06 17:21:33
 */
public interface IEnergyDataFilter {

    String READ_TYPE = "readType";

    String ENERGY_DATA_READ_TYPE = "ecp-admin.energyData.readType";

    class EnergyDataExportFilter implements ValueFilter {

        private Map<String, String> readTypeMap;

        public EnergyDataExportFilter() {
            readTypeMap = DictHelper.i().stringVlMap(ENERGY_DATA_READ_TYPE);
        }

        @Override
        public Object process(Object object, String name, Object value) {
            if (StringUtils.equals(name, READ_TYPE)) {
                return CommonUtils.orElse(readTypeMap.get(CommonUtils.toString(value)), value);
            }
            return value;
        }

    }

    class EnergyDataExtExportFilter implements ValueFilter {

        private Map<String, String> readTypeMap;

        private IMeterDeviceFilter.MeterDeviceExportFilter meterDeviceExportFilter;

        public EnergyDataExtExportFilter() {
            readTypeMap = DictHelper.i().stringVlMap(ENERGY_DATA_READ_TYPE);
            meterDeviceExportFilter = new IMeterDeviceFilter.MeterDeviceExportFilter();
        }

        @Override
        public Object process(Object object, String name, Object value) {
            if (StringUtils.equals(name, READ_TYPE)) {
                return CommonUtils.orElse(readTypeMap.get(CommonUtils.toString(value)), value);
            }

            return meterDeviceExportFilter.process(object, name, value);
        }

    }

    class EnergyDataUploadFilter implements ValueFilter {

        private Map<String, String> readTypeMap;

        public EnergyDataUploadFilter() {
            readTypeMap = DictHelper.i().stringLvMap(ENERGY_DATA_READ_TYPE);
        }

        @Override
        public Object process(Object object, String name, Object value) {
            if (StringUtils.equals(name, READ_TYPE)) {
                return CommonUtils.orElse(readTypeMap.get(CommonUtils.toString(value)), value);
            }
            return value;
        }

    }

}